# @Time : 2021/4/3 9:58
# @Author : Fioman 
# @Phone : 13149920693
"""
项目用到的配置文件,主要用来保存项目的一些配置,例如是否是调试模式,一些路径配置问题
"""
import os
import sys
from enum import Enum

# 项目名称
PROJECT_NAME = "xinfengjw01"

# 使用的数据库名称
DATABASE_NAME = "params_{}".format(PROJECT_NAME)
# 是否是开发者模式
DEVELOP = True if len(sys.argv) >= 2 else False

# 主线程是否在运行的标志
IS_MAIN_ALIVE = False

# 项目的根目录,也就是python目录所在的绝对路径
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
WEB_PATH = os.path.join(BASE_DIR, "web")
ZMC_LIB_PATH = os.path.join(BASE_DIR, r'dll\zmotion.dll')
AUX_ZMC_LIB_PATH = os.path.join(BASE_DIR, r'dll\zauxdll.dll')
CAMERA_LIB_PATH = os.path.join(BASE_DIR, r"dll\MvCameraControl.dll")
CODE_LIB_PATH = os.path.join(BASE_DIR, r"dll\MvCodeReaderCtrl.dll")

MSG_RECV_PATH = os.path.join(BASE_DIR, r"hd_socket\message_recv.xml")
MSG_SEND_PATH = os.path.join(BASE_DIR, r"hd_socket\message_send.xml")
EAP_SEND_MOCK_PATH = os.path.join(BASE_DIR, r"hd_socket\eap_mock_message_send.xml")

DEBUG_DIR = os.path.join(BASE_DIR, "debug")
# 10. 标定的图片的保存目录
CALIBRATION_DIR = r"D:\raw_tool\raw_calibration"
# 11. 图像拼接使用的目录
IMAGE_JOINT_DIR = r"D:\raw_tool\raw_joint"
# 12. 统计物料宽高的目录
COUNT_BOARD_SIZE_DIR = r"D:\raw_tool\raw_joint\count_board_size"
# 13. 铡刀终点检测的图片保存
# 16. 保存文件,界面上点击保存的时候,会将文件,保存到这个目录下
FILE_SAVE_DIR = r"D:\file_save"  # 保存文件的目录

DATA_BASE_DUMP_DIR = r"D:\db_data\data_dump"
# 18. 数据库导入的目录
DATA_BASE_IMPORT_DIR = r"D:\db_data\data_import"
CUTTER_CAM_CAL_DIR = r"D:\raw_tool\cutter_raw\raw_calc"

MYSQL_DEBUG_DIR = os.path.join(BASE_DIR, "mysql_debug")

# 然后就是项目启动的时候自检,这些路径是否都存在,如果不存在就创建
filePathList = [
    CUTTER_CAM_CAL_DIR,  # 2
    DEBUG_DIR,  # 9
    CALIBRATION_DIR,  # 10
    IMAGE_JOINT_DIR,  # 11
    COUNT_BOARD_SIZE_DIR,  # 12
    FILE_SAVE_DIR,  # 16
    DATA_BASE_DUMP_DIR,  # 17
    DATA_BASE_IMPORT_DIR,  # 18
    MYSQL_DEBUG_DIR
]
for filePath in filePathList:
    if not os.path.exists(filePath):
        os.makedirs(filePath)

# 图像的一些目录,在自动作业开始之前,根据order_id去创建,包括横拼,横拼的后面加一个hp,然后正常的是sp
first_cut_board_dir_2pin = None
size_check_ok_dir_2pin = None
raw_ok_dir_2pin = None
raw_cut_dir_2pin = None
totalboard_error_dir_2pin = None
raw_fail_dir_2pin = None

first_cut_board_dir_1pin = None
size_check_ok_dir_1pin = None
raw_ok_dir_1pin = None
raw_cut_dir_1pin = None
totalboard_error_dir_1pin = None
raw_fail_dir_1pin = None
# 铡刀目录
cutter_raw_begin_dir = None
cutter_raw_begin_res_dir = None
cutter_raw_final_dir = None
cutter_raw_final_res_dir = None


class RotatedType(Enum):
    ClockWise = 0,  # 顺时针
    NoRotated = 1,  # 逆时针
    CounterClockWise = 2,  # 不旋转


class RunState(Enum):
    """
    设备的运行停止状态
    """
    Stop = 0
    Running = 1


class PcSignal(Enum):
    """
    设备实时信号类型
    """
    POWER = 0
    PRODUCT = 1
    WAITMATERIAL = 2
    TOTALALARM = 3
    EMERGENCYSTOP = 4
    STOPLINE = 5
    AUTOMANUAL = 6
    MATERIALOK = 7
    UPDATEPLANOK = 8
    DELETEPLANOK = 9
    SCANLOTUPLOAD = 10


class AlarmType(Enum):
    """
    Eap上报的报警类型
    """
    HOLE_ALARM_1 = "上料控制器通信异常"
    HOLE_ALARM_2 = "裁切机控制器通信异常"
    HOLE_ALARM_3 = "铡刀控制器通信异常"
    HOLE_ALARM_4 = "相机组通信异常"
    HOLE_ALARM_5 = "铡刀检测报警"
    HOLE_ALARM_6 = "图像处理异常"
    HOLE_ALARM_7 = "上料控制器急停报警"
    HOLE_ALARM_8 = "裁切机控制器急停报警"
    HOLE_ALARM_9 = "铡刀控制器急停报警"


class AlarmState(Enum):
    """
    报警发生和复位状态
    报警为1,复位为0
    """
    Happen = 1
    Reset = 0


class PowerState(Enum):
    """
    设备上机状态,设备通电为1,设备停机为停机状态
    """
    Stop = 0
    PowerOn = 1


class ProductState(Enum):
    """
    设备生产状态, 生产开始/结束
    """
    Over = 0
    Begin = 1


class OperateMode(Enum):
    """
    设别的操作模式,0为手动模式,1为自动模式
    注意大坑,枚举的时候不能使用逗号,如果使用逗号,后面的0或者1会被当成是元组
    """
    localMode = 0
    eapMode = 1


# 从Eap那里接收到的工单数据,主函数用这个来切换工单
orderDownloadFromEap = None
